//ContactManagerPanel.java

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

import java.util.Scanner;
import java.io.*;

public class ContactManagerPanel extends JPanel {

	private JButton AddButton, modifyButton, deleteButton; 
	ContactCollection contact = new ContactCollection();
	private JLabel Firstn_lbl, Lastn_lbl, pos_lbl, depart_lbl, coname_lbl, address_lbl, telnum_lbl, faxnum_lbl, monum_lbl, email_lbl, homp_lbl, View_lbl;
	private JTextField Firstn_txt, Lastn_txt, pos_txt, depart_txt, coname_txt, address_txt, telnum_txt, faxnum_txt, mobnum_txt, email_txt, homp_txt;
	private JTabbedPane tab;
	

	/**
	 * Create the panel.
	 */
	private JPanel ViewPanel, DisplayPanel, AddPanel, SearchPanel, PasswordPanel;
	
	private JTextArea ViewTArea;
	public ContactManagerPanel() {
		setLayout(null);
		setPreferredSize(new Dimension(800, 500));	
		
		ButtonListener listener = new ButtonListener();//��ư�̺�Ʈ ó���� ������
		
		ViewPanel = new JPanel();
		ViewPanel.setBounds(453, 0, 347, 500);
		add(ViewPanel);
		ViewPanel.setLayout(null);
		
		View_lbl = new JLabel("View");
		View_lbl.setFont(new Font("굴림", Font.BOLD, 16));
		View_lbl.setBounds(28, 35, 52, 28);
		ViewPanel.add(View_lbl);
		
	    ViewTArea = new JTextArea();
	    ViewTArea.setBounds(12, 73, 323, 389);
		ViewPanel.add(ViewTArea);

		modifyButton = new JButton("수정");

		modifyButton.setBounds(154, 472, 72, 23);
		ViewPanel.add(modifyButton);

		deleteButton = new JButton("삭제");


		modifyButton.addActionListener(listener);	

		deleteButton.setBounds(263, 472, 72, 23);
		ViewPanel.add(deleteButton);
		deleteButton.addActionListener(listener);
		
		tab = new JTabbedPane(JTabbedPane.LEFT);
		tab.setBounds(0, 20, 453, 470);
		add(tab, BorderLayout.CENTER);
		

		//Displaypanel �� ��� �߰�

		DisplayPanel = new JPanel();
		tab.addTab("Display", null, DisplayPanel, null);
		DisplayPanel.setPreferredSize(new Dimension(400,300));
		DisplayPanel.setLayout(null);
		

		JLabel lblNewLabel = new JLabel("전화번호부");
		lblNewLabel.setFont(new Font("굴림", Font.BOLD, 15));
		lblNewLabel.setBounds(30, 22, 96, 33);
		DisplayPanel.add(lblNewLabel);
		
		JList list = new JList();
		list.setBounds(30, 65, 313, 380);
		DisplayPanel.add(list);

		//Addpanel �� ��� �߰�		

		AddPanel = new JPanel();
		tab.addTab("Add", null, AddPanel, null);
		AddPanel.setPreferredSize(new Dimension(400,300));
		AddPanel.setLayout(null);
		

		AddButton = new JButton("추가");

		AddButton.setBounds(266, 437, 97, 23);
		AddPanel.add(AddButton);
		
		AddButton.addActionListener(listener);//add ��ư �̺�Ʈ
		
		Firstn_lbl = new JLabel("First name");
		Firstn_lbl.setBounds(12, 48, 80, 15);
		AddPanel.add(Firstn_lbl);
		
		Lastn_lbl = new JLabel("Last name");
		Lastn_lbl.setBounds(12, 82, 80, 15);
		AddPanel.add(Lastn_lbl);
		
		Firstn_txt = new JTextField();
		Firstn_txt.setBounds(129, 42, 116, 21);
		AddPanel.add(Firstn_txt);
		Firstn_txt.setColumns(10);
		
		Lastn_txt = new JTextField();
		Lastn_txt.setBounds(129, 76, 116, 21);
		AddPanel.add(Lastn_txt);
		Lastn_txt.setColumns(10);
		
		pos_lbl = new JLabel("Position");
		pos_lbl.setBounds(12, 120, 57, 15);
		AddPanel.add(pos_lbl);
		
		pos_txt = new JTextField();
		pos_txt.setColumns(10);
		pos_txt.setBounds(129, 114, 116, 21);
		AddPanel.add(pos_txt);
		
		depart_lbl = new JLabel("Department");
		depart_lbl.setBounds(12, 155, 80, 15);
		AddPanel.add(depart_lbl);
		
		depart_txt = new JTextField();
		depart_txt.setColumns(10);
		depart_txt.setBounds(129, 149, 116, 21);
		AddPanel.add(depart_txt);
		
		coname_lbl = new JLabel("Company name");
		coname_lbl.setBounds(12, 191, 97, 15);
		AddPanel.add(coname_lbl);
		
		coname_txt = new JTextField();
		coname_txt.setColumns(10);
		coname_txt.setBounds(129, 185, 116, 21);
		AddPanel.add(coname_txt);
		
		address_lbl = new JLabel("Address");
		address_lbl.setBounds(12, 225, 80, 15);
		AddPanel.add(address_lbl);
		
		address_txt = new JTextField();
		address_txt.setColumns(10);
		address_txt.setBounds(129, 219, 234, 21);
		AddPanel.add(address_txt);
		
		telnum_lbl = new JLabel("Telephone number");
		telnum_lbl.setBounds(12, 258, 116, 15);
		AddPanel.add(telnum_lbl);
		
		telnum_txt = new JTextField();
		telnum_txt.setColumns(10);
		telnum_txt.setBounds(129, 252, 155, 21);
		AddPanel.add(telnum_txt);
		
		faxnum_lbl = new JLabel("Fax number");
		faxnum_lbl.setBounds(12, 291, 80, 15);
		AddPanel.add(faxnum_lbl);
		
		faxnum_txt = new JTextField();
		faxnum_txt.setColumns(10);
		faxnum_txt.setBounds(129, 285, 116, 21);
		AddPanel.add(faxnum_txt);
		
		monum_lbl = new JLabel("Mobile number");
		monum_lbl.setBounds(12, 325, 97, 15);
		AddPanel.add(monum_lbl);
		
		mobnum_txt = new JTextField();
		mobnum_txt.setColumns(10);
		mobnum_txt.setBounds(129, 319, 155, 21);
		AddPanel.add(mobnum_txt);
		
		email_lbl = new JLabel("Email address");
		email_lbl.setBounds(12, 363, 97, 15);
		AddPanel.add(email_lbl);
		
		email_txt = new JTextField();
		email_txt.setColumns(10);
		email_txt.setBounds(129, 357, 217, 21);
		AddPanel.add(email_txt);
		
		homp_lbl = new JLabel("Homepage");
		homp_lbl.setBounds(12, 401, 97, 15);
		AddPanel.add(homp_lbl);
		
		homp_txt = new JTextField();
		homp_txt.setColumns(10);
		homp_txt.setBounds(129, 395, 217, 21);
		AddPanel.add(homp_txt);

		//SearchPanel �� ��� ����

		SearchPanel = new JPanel();
		tab.addTab("Search", null, SearchPanel, null);
		SearchPanel.setPreferredSize(new Dimension(400,300));
		SearchPanel.setLayout(null);

		//PasswordPanel �� ��� ����

		PasswordPanel = new JPanel();
		tab.addTab ("Password", null, PasswordPanel, null);		
		PasswordPanel.setPreferredSize(new Dimension(400,300));
		PasswordPanel.setLayout(null);
				
	}
	
	private class ButtonListener implements ActionListener 
	{
		public void actionPerformed(ActionEvent event)
		{
			if(event.getSource() == AddButton) // 연락처 등록 버튼
			{
			contact.addContact(Firstn_txt.getText(), Lastn_txt.getText(), pos_txt.getText(), depart_txt.getText(),coname_txt.getText(), address_txt.getText(), telnum_txt.getText(), faxnum_txt.getText(), mobnum_txt.getText(), email_txt.getText(), homp_txt.getText());
			ViewTArea.setText(contact.toString()); 			
			
			Firstn_txt.setText("");
			Lastn_txt.setText("");
			pos_txt.setText("");
			depart_txt.setText("");
			coname_txt.setText("");
			address_txt.setText("");
			telnum_txt.setText("");
			faxnum_txt.setText("");
			mobnum_txt.setText("");
			email_txt.setText("");
			homp_txt.setText("");// 텍스트 필드 초기화
			}
			if(event.getSource() == modifyButton) // 연락처 등록 버튼
			{
			
			}
			if(event.getSource() == deleteButton) // 연락처 등록 버튼
			{
				
			}
		}
	}

}
